const path = require('node:path')

module.exports = (codeConfig, utils) => {
  const { exportExcelApiConfig, hasModifyDialog } = codeConfig.apiConfigStates
  const code = `
    import { provide, reactive } from 'vue'
    import type { Store } from '../types'
    
    export const useStore = () => {
      const store = reactive<Store>({
        listPageRef: undefined,
        query: {},
        tableData: [],
        total: 0,
        exportIds: [],
        ${exportExcelApiConfig ? 'exportExcelLoading: false,' : ''}
        ${
          hasModifyDialog ?
            `
              visibleDialogModify: false,
              isModify: false,
              modifyData: {},
            ` :
            ''
        }
      })
      provide('${codeConfig.moduleName}Store', store)
      return store
    }  
  `
  utils.writeFile(path.join(codeConfig.modulePath, 'hooks', 'use-store.ts'), code)
}
